﻿
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Xml.Serialization
<Serializable()> Public Class Project
    Private m_Name As String = ""

    Private m_IsDep As Boolean
    Private m_MaxCon As Integer
    Private m_PostPath As String

  
    Private m_AERMODOUTFileName As String


    Private m_Receptor As New Receptor

    Private m_AerageTime As New AerageingTime

    Private m_RectableGroups(-1) As RectableGroups
    Private m_PostGroups(-1) As PostGroups
    Private m_MaxTableGroups(-1) As MaxTalbeGroups
    Private m_Groups(-1) As Group

    Property Receptor() As Receptor
        Get
            Return Me.m_Receptor
        End Get
        Set(ByVal value As Receptor)
            Me.m_Receptor = value
        End Set
    End Property
    Property IsDep() As Boolean
        Get
            Return Me.m_IsDep
        End Get
        Set(ByVal value As Boolean)
            Me.m_IsDep = value
        End Set
    End Property

    Property AerageTime() As AerageingTime
        Get
            Return Me.m_AerageTime
        End Get
        Set(ByVal value As AerageingTime)
            Me.m_AerageTime = value
        End Set
    End Property
    Property MaxCon() As Integer
        Get
            Return Me.m_MaxCon
        End Get
        Set(ByVal value As Integer)
            Me.m_MaxCon = value
        End Set
    End Property
    Property PostPath() As String
        Get
            Return Me.m_PostPath
        End Get
        Set(ByVal value As String)
            Me.m_PostPath = value
        End Set
    End Property

    Property AERMODOUTFileName() As String
        Get
            Return Me.m_AERMODOUTFileName
        End Get
        Set(ByVal value As String)
            Me.m_AERMODOUTFileName = value
        End Set
    End Property

    ''' <summary>
    ''' 计算结果中的污染源分组数组
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property RectableGroups() As RectableGroups()
        Get
            Return Me.m_RectableGroups
        End Get
        Set(ByVal value As RectableGroups())
            Me.m_RectableGroups = value
        End Set
    End Property
    Property PostGroups() As PostGroups()
        Get
            Return Me.m_PostGroups
        End Get
        Set(ByVal value As PostGroups())
            Me.m_PostGroups = value
        End Set
    End Property
    Property MaxTableGroups() As MaxTalbeGroups()
        Get
            Return Me.m_MaxTableGroups
        End Get
        Set(ByVal value As MaxTalbeGroups())
            Me.m_MaxTableGroups = value
        End Set
    End Property
    ''' <summary>
    ''' 方案的名称
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property Name() As String
        Get
            Return m_Name
        End Get
        Set(ByVal value As String)
            m_Name = value
        End Set
    End Property
    Property Groups() As Group()
        Get
            Return Me.m_Groups
        End Get
        Set(ByVal value As Group())
            Me.m_Groups = value
        End Set
    End Property


    Public Function GetDataRectable(ByVal strAERMODOUT As String(), ByVal AermodVersion As String) As Boolean
        '根据结果文件找出各点高值来
        ReDim m_RectableGroups(Me.m_Groups.Length - 1)
        For i As Integer = 0 To m_RectableGroups.Length - 1 '根据分组求
            m_RectableGroups(i) = New RectableGroups
            If Me.m_RectableGroups(i).GetData(strAERMODOUT, Me.m_Groups(i), Me.m_Receptor, Me.m_IsDep, Me.m_AerageTime, Me.m_MaxCon, AermodVersion) = False Then '期间平均
                Return False
            End If
        Next
        Return True
    End Function
    ''' <summary>
    ''' 根据计算结果获取数据
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetAllData() As Boolean
        Dim version As String = "07026"
        Dim strAERMODOUT(-1) As String
        Dim strLine As String
        Try
            FileOpen(1, Me.m_AERMODOUTFileName, OpenMode.Input) '打开文件
            Do Until EOF(1)
                strLine = LineInput(1) '读取一行
                ReDim Preserve strAERMODOUT(strAERMODOUT.Length)
                strAERMODOUT(strAERMODOUT.Length - 1) = strLine
                If strLine.Contains("AERMOD - VERSION 09292") Then
                    version = "09292"
                End If
            Loop
            FileClose(1) '关闭文件
            Me.GetDataRectable(strAERMODOUT, version) '获取各点高值
        Catch ex As Exception
            FileClose(1) '关闭文件
            MsgBox(ex.Message)
            If ex.Message.Contains("转换无效") Then
                MsgBox("可能是您输入的源强太大，已超出Aermod的数值范围，请修改源强!")
                Return False
            End If
            MsgBox("数据文件出错，请检查数据文件的格式!")
            Return False
        Finally
            FileClose(1) '关闭文件
        End Try
        'Me.m_AermodResults(iIndexPollution).PostResult.GetDataFromPostBin(Control, iIndexPollution, Receptor, Me.m_Source.Groups) '获取POST文件的数据
        'Me.m_AermodResults(iIndexPollution).Name = Me.Control.AllPolluts.AllSelectPollut(iIndexPollution).Name
        'Me.m_AermodResults(i).PostResult.SetCareSuperData(Control, i, Receptor) '设置关心点超标分析
        'Me.m_AermodResults(i).PostResult.SetGridSuperData(Control, i, Receptor) '设置网格点超标分析
        Return True
    End Function
End Class
